#ifndef __BSP_CAN_H
#define __BSP_CAN_H

#include "struct_typedef.h"

// #define CHASSIS_CAN hcan1
// #define ANCILLARY_CAN hcan2
#ifdef __cplusplus
extern "C"{
#endif

#ifdef __cplusplus
/*******上下双板时（云台）可用*********/
typedef union 
{
    uint8_t s[4];
    fp32 f;
} Chassis_Order;

//typedef union 
//{
//    uint8_t s[4];
//    fp32 f;
//} Yaw_Pitch;

typedef struct
{
uint8_t if_shoot;
}chassis_to_gimbal_t;

/*******上下双板时（底盘）可用*********/
typedef struct
{
  Chassis_Order vx_set;          
  Chassis_Order vy_set;                 
  Chassis_Order wz_set;
  uint8_t if_open;
  uint8_t mode;
  uint8_t id;  
} chassis_order_measure_t;

//typedef union
//{
//		uint8_t s[4];
//    fp32 f;
//}coordinate_system;


///**********通用**********/
//typedef struct
//{   
//	fp32 Cap_input_vol;
//	fp32 Cap_voltage;
//	fp32 Cap_current;
//	uint16_t Cap_power;
//} Chassis_Power_t;

typedef union
{
    uint8_t s[4];
    fp32 f;
}mpu6050_accel_t;

typedef union
{
    uint8_t s[4];
    fp32 f;
}mpu6050_angle_t;

typedef struct
{
    mpu6050_accel_t accel_pitch;
    mpu6050_accel_t accel_roll;
    mpu6050_angle_t pitch_angle;
    mpu6050_angle_t roll_angle;

}mpu6050_send_data_t;
/****不同电机挂载在不同CAN线上时需修改*****/
enum CAN1_msg_ID
{
	CAN1_3508_LF_ID = 0x201,
	CAN1_3508_LB_ID = 0x202,
	CAN1_3508_RB_ID = 0x203,
 	CAN1_3508_RF_ID = 0x204,
    mpu6050_ID =  0x208,
};

enum CAN2_msg_ID
{
	CAN2_Lifting_Motor_ID = 0x201,
	CAN2_Front_Motor_ID = 0x202,
	CAN2_GOLD_Motor_ID = 0x203,
	CAN2_Side_Motor_ID = 0x204,
	CAN2_Ore_Motor_ID = 0x205,
};


//可在此处加入所需电机编号
enum motor_ID
{
	LF,  //=0
	LB,  //=1
	RB,  //=2
	RF,  //=3 
//	LIFTING, //=4
//	GOLD,//5
//	FRONT,  //=6
//	SIDE,  //=7
//	ORE,  //=8
	UPMOTOR_L,
	UPMOTOR_R,
	FRONTMOTOR_L,
	FRONTMOTOR_R,
};

extern void CAN1_200_cmd_motor(int16_t can1_motor1, int16_t can1_motor2, int16_t can1_motor3, int16_t can1_motor4);
extern void CAN1_1FF_cmd_motor(int16_t can1_motor5, int16_t can1_motor6, int16_t can1_motor7, int16_t can1_motor8);
extern void CAN2_200_cmd_motor(int16_t can2_motor1, int16_t can2_motor2, int16_t can2_motor3, int16_t can2_motor4);
extern void CAN2_1FF_cmd_motor(int16_t can2_motor5, int16_t can2_motor6, int16_t can2_motor7, int16_t can2_motor8);
extern void CAN_cmd_chassis_reset_ID(void);
extern void CAN1_1FF_cmd_motor_send_wz_info(int16_t can1_motor5, int16_t can1_motor6, fp32 info);
extern void CAN1_301_send_vxvy_info(fp32 vx_set, fp32 vy_set);
void CAN_CMD_CAP(uint16_t motor1);
void CAN_CMD_ROBO_CAP(uint8_t dischargecmd,uint8_t ctrlmode,uint16_t chassis_power_buff,uint16_t chassis_power_buff_limit,uint16_t chassis_power_limit);
extern const chassis_to_gimbal_t  *get_if_revolver_point(void);
extern void CAN1_send_state_info(uint8_t reset,uint8_t Auto, uint8_t Spin ,uint8_t IfShift ,uint8_t OBLI);
extern const chassis_order_measure_t *get_Gimbal_Oreder();
extern bool_t if_speed_update;
extern fp32 speed_offest;
extern void CAN_send_mpu6050_measure(fp32 Accel_pitch,fp32 Accel_roll,fp32 Pitch_angle,fp32 Roll_angle);

#endif	
extern void CAN_CMD_Shoot_on(uint8_t shoot);
extern void CAN1_send_bullet_speed(fp32 speed,uint8_t shoot_out,uint8_t chassis_out);
/**********通用**********/
typedef struct
{   
	fp32 Cap_input_vol;
	fp32 Cap_voltage;
	fp32 Cap_current;
	uint16_t Cap_power;
} Chassis_Power_t;

typedef struct
{   
	uint8_t warning;
	uint8_t DischargeStop;
	uint16_t chassis_power;
	uint16_t ele_quantity;
} robofuture_cap_measure_t;


extern void can_filter_init(void);	

typedef union
{
		uint8_t s[4];
    fp32 f;
}coordinate_system;

typedef union 
{
    uint8_t s[4];
    fp32 f;
} Yaw_Pitch;

typedef union 
{
    uint8_t s[4];
    fp32 f;
}Shoot;

typedef union
{
	uint8_t s[4];
	fp32 f;
}rate_t;

typedef union
{
	uint8_t s[2];
	uint16_t u;
}speed_set_t;

typedef struct
{
	Yaw_Pitch yaw_angle;
  Yaw_Pitch pitch_angle;
	coordinate_system x_coordinate;
	coordinate_system y_coordinate;
	coordinate_system pre_x_coordinate;
	coordinate_system pre_y_coordinate;
	rate_t radius;//fir_speed;
	uint8_t reset;
	uint8_t IfFirc;
	uint8_t IfShift;
	uint8_t Auto;                 
  uint8_t Spin;  
	speed_set_t speed_set;
	uint8_t vision_mode;
} UI_order_to_chassis;
extern UI_order_to_chassis UI_Measure;
extern const UI_order_to_chassis *get_UI_measure(void);
extern const Chassis_Power_t *get_cap_measure_point(void);
extern const robofuture_cap_measure_t *get_robo_cap_measure_point(void);
#ifdef __cplusplus
}
#endif

#endif




